/**
 * 
 */
package jmine.tec.report.impl;

import java.io.Serializable;
import java.util.Map;

import jmine.tec.report.DataColumn;
import jmine.tec.report.metadata.impl.UnmodifiableColumnMetaData;

/**
 * Abstract base implementation of {@link DataColumn}
 * 
 * @author takeshi
 * @version 21/08/2007
 */
public abstract class AbstractDataColumn implements DataColumn, Serializable {

    private final String key;

    private final String name;

    /**
     * C'tor
     * 
     * @param key String
     * @param name String
     */
    public AbstractDataColumn(final String key, final String name) {
        super();
        this.key = key;
        this.name = name;
    }

    /**
     * Tests this object and another for equality
     * 
     * @param obj the other object
     * @return boolean
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (this.getClass() != obj.getClass()) {
            return false;
        }
        final AbstractDataColumn other = (AbstractDataColumn) obj;
        if (this.key == null) {
            if (other.key != null) {
                return false;
            }
        } else if (!this.key.equals(other.key)) {
            return false;
        }
        if (this.name == null) {
            if (other.name != null) {
                return false;
            }
        } else if (!this.name.equals(other.name)) {
            return false;
        }
        return true;
    }

    /**
     * @return a chave que identifica a coluna.
     */
    public final String getKey() {
        return this.key;
    }

    /**
     * O nome da coluna
     * 
     * @return String
     */
    public final String getName() {
        return this.name;
    }

    /**
     * Retorna um view deste DataColumn
     * 
     * @param params os par�metros
     * @return DataColumn
     */
    public SimpleDataColumn getView(final Map<String, Object> params) {
        return new SimpleDataColumn(this.getKey(), this.getName(), new UnmodifiableColumnMetaData(this.getMetaData()));
    }

    /**
     * @return hashcode
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((this.key == null) ? 0 : this.key.hashCode());
        result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
        return result;
    }

}
